﻿$(function() {
    BouCreate.init();
    Utils.textBoxsOnEnter(BouCreate.Create);
});


var BouCreate =
{
    init: function() {
        $("#btnSave").click(this.Create);
        $("#username").focus();
        $(document).keyup(function(e) {
            if (e.keyCode == 27) {
                window.parent.utility.closePopUpUrl();
            }
        });
    },
    Create: function() {
        var id = $("#username");
        var pwd = $("#password");
        var cwd = $("#conpassword");

        targetFunction = (parent != undefined) ? parent.ErrorHelper : ErrorHelper;
        targetFunction.checkNonNull(id, m.Err0001);
        targetFunction.checkNonNull(pwd, m.Err0002);
        targetFunction.checkNonNull(cwd, m.Err0007);
        if (!targetFunction.hasError) {
            targetFunction.checkIsEq(pwd, cwd, m.Err0008);
            if (targetFunction.hasError) { cwd.val(''); }
        }

        if (!targetFunction.popUpIfError()) {
            var param = { username: id.val(), password: pwd.val() };
            var cb = Utils.getCBfunction('Bou');
            var ecb = function() { $("#username").focus(); };
            window.parent.utility.ajaxext("BouService/Create", param, "POST", cb, ecb);
        }
    }
};
